// $ANTLR 3.3 Nov 30, 2010 12:45:30 /home/matthijs/paf/RichRail.g 2011-05-01 16:18:20

	package com.richrail.console.dsl;
	
	import org.antlr.runtime.BitSet;
import org.antlr.runtime.MismatchedSetException;
import org.antlr.runtime.NoViableAltException;
import org.antlr.runtime.Parser;
import org.antlr.runtime.ParserRuleReturnScope;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.RecognizerSharedState;
import org.antlr.runtime.Token;
import org.antlr.runtime.TokenStream;

import com.richrail.console.commands.AddCommand;
import com.richrail.console.commands.DeleteCommand;
import com.richrail.console.commands.GetNumSeatsCommand;
import com.richrail.console.commands.NewTrainCommand;
import com.richrail.console.commands.NewWagonCommand;
import com.richrail.console.commands.RemoveCommand;
import com.richrail.model.entities.DepotStorage;

public class RichRailParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "ID", "NUMBER", "WS", "';'", "'new'", "'train'", "'wagon'", "'numseats'", "'add'", "'to'", "'getnumseats'", "'delete'", "'remove'", "'from'"
    };
    public static final int EOF=-1;
    public static final int T__7=7;
    public static final int T__8=8;
    public static final int T__9=9;
    public static final int T__10=10;
    public static final int T__11=11;
    public static final int T__12=12;
    public static final int T__13=13;
    public static final int T__14=14;
    public static final int T__15=15;
    public static final int T__16=16;
    public static final int T__17=17;
    public static final int ID=4;
    public static final int NUMBER=5;
    public static final int WS=6;

    // delegates
    // delegators


        public RichRailParser(TokenStream input) {
            this(input, new RecognizerSharedState());
        }
        public RichRailParser(TokenStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        

    @Override
	public String[] getTokenNames() { return RichRailParser.tokenNames; }
    @Override
	public String getGrammarFileName() { return "/home/matthijs/RichRail.g"; }


    	// Just make it public, getter and setter in this case is
    	// nothing more than a glorified public member.
    	public String response;
    	
    	// We should only have one instance of each command in this case.
    	// Why not making them singletons? Because this works just fine.
    	// No need to use the Singleton pattern unless it is really necessary,
    	// because it also has a lot of drawbacks.
    	private static NewTrainCommand newTrainCommand = new NewTrainCommand();
    	private static NewWagonCommand newWagonCommand = new NewWagonCommand();
    	private static AddCommand addCommand = new AddCommand();
    	private static GetNumSeatsCommand getNumSeatsCommand = new GetNumSeatsCommand();
    	private static DeleteCommand deleteCommand = new DeleteCommand();
    	private static RemoveCommand removeCommand = new RemoveCommand();
    	
    	public static void setDepotStorage(DepotStorage depotStorage)
    	{
    		newTrainCommand.setDepotStorage(depotStorage);
    		newWagonCommand.setDepotStorage(depotStorage);
    		addCommand.setDepotStorage(depotStorage);
    		getNumSeatsCommand.setDepotStorage(depotStorage);
    		deleteCommand.setDepotStorage(depotStorage);
    		removeCommand.setDepotStorage(depotStorage);
    	}



    // $ANTLR start "command"
    // /home/matthijs/paf/RichRail.g:43:1: command : ( newcommand | addcommand | getcommand | delcommand | remcommand ) ( ';' )? ;
    public final void command() throws RecognitionException {
        try {
            // /home/matthijs/paf/RichRail.g:43:8: ( ( newcommand | addcommand | getcommand | delcommand | remcommand ) ( ';' )? )
            // /home/matthijs/paf/RichRail.g:44:2: ( newcommand | addcommand | getcommand | delcommand | remcommand ) ( ';' )?
            {
            // /home/matthijs/paf/RichRail.g:44:2: ( newcommand | addcommand | getcommand | delcommand | remcommand )
            int alt1=5;
            switch ( input.LA(1) ) {
            case 8:
                {
                alt1=1;
                }
                break;
            case 12:
                {
                alt1=2;
                }
                break;
            case 14:
                {
                alt1=3;
                }
                break;
            case 15:
                {
                alt1=4;
                }
                break;
            case 16:
                {
                alt1=5;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 1, 0, input);

                throw nvae;
            }

            switch (alt1) {
                case 1 :
                    // /home/matthijs/paf/RichRail.g:44:3: newcommand
                    {
                    pushFollow(FOLLOW_newcommand_in_command39);
                    newcommand();

                    state._fsp--;


                    }
                    break;
                case 2 :
                    // /home/matthijs/paf/RichRail.g:44:16: addcommand
                    {
                    pushFollow(FOLLOW_addcommand_in_command43);
                    addcommand();

                    state._fsp--;


                    }
                    break;
                case 3 :
                    // /home/matthijs/paf/RichRail.g:44:29: getcommand
                    {
                    pushFollow(FOLLOW_getcommand_in_command47);
                    getcommand();

                    state._fsp--;


                    }
                    break;
                case 4 :
                    // /home/matthijs/paf/RichRail.g:44:42: delcommand
                    {
                    pushFollow(FOLLOW_delcommand_in_command51);
                    delcommand();

                    state._fsp--;


                    }
                    break;
                case 5 :
                    // /home/matthijs/paf/RichRail.g:44:55: remcommand
                    {
                    pushFollow(FOLLOW_remcommand_in_command55);
                    remcommand();

                    state._fsp--;


                    }
                    break;

            }

            // /home/matthijs/paf/RichRail.g:44:67: ( ';' )?
            int alt2=2;
            int LA2_0 = input.LA(1);

            if ( (LA2_0==7) ) {
                alt2=1;
            }
            switch (alt2) {
                case 1 :
                    // /home/matthijs/paf/RichRail.g:44:67: ';'
                    {
                    match(input,7,FOLLOW_7_in_command58); 

                    }
                    break;

            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "command"


    // $ANTLR start "newcommand"
    // /home/matthijs/paf/RichRail.g:46:1: newcommand : ( newtraincommand | newwagoncommand );
    public final void newcommand() throws RecognitionException {
        try {
            // /home/matthijs/paf/RichRail.g:46:11: ( newtraincommand | newwagoncommand )
            int alt3=2;
            int LA3_0 = input.LA(1);

            if ( (LA3_0==8) ) {
                int LA3_1 = input.LA(2);

                if ( (LA3_1==9) ) {
                    alt3=1;
                }
                else if ( (LA3_1==10) ) {
                    alt3=2;
                }
                else {
                    NoViableAltException nvae =
                        new NoViableAltException("", 3, 1, input);

                    throw nvae;
                }
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 3, 0, input);

                throw nvae;
            }
            switch (alt3) {
                case 1 :
                    // /home/matthijs/paf/RichRail.g:47:2: newtraincommand
                    {
                    pushFollow(FOLLOW_newtraincommand_in_newcommand68);
                    newtraincommand();

                    state._fsp--;


                    }
                    break;
                case 2 :
                    // /home/matthijs/paf/RichRail.g:47:20: newwagoncommand
                    {
                    pushFollow(FOLLOW_newwagoncommand_in_newcommand72);
                    newwagoncommand();

                    state._fsp--;


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "newcommand"


    // $ANTLR start "newtraincommand"
    // /home/matthijs/paf/RichRail.g:49:1: newtraincommand : 'new' 'train' ( ID )? ;
    public final void newtraincommand() throws RecognitionException {
        Token ID1=null;

        try {
            // /home/matthijs/paf/RichRail.g:49:16: ( 'new' 'train' ( ID )? )
            // /home/matthijs/paf/RichRail.g:50:2: 'new' 'train' ( ID )?
            {
            match(input,8,FOLLOW_8_in_newtraincommand81); 
            match(input,9,FOLLOW_9_in_newtraincommand83); 
            // /home/matthijs/paf/RichRail.g:50:16: ( ID )?
            int alt4=2;
            int LA4_0 = input.LA(1);

            if ( (LA4_0==ID) ) {
                alt4=1;
            }
            switch (alt4) {
                case 1 :
                    // /home/matthijs/paf/RichRail.g:50:16: ID
                    {
                    ID1=(Token)match(input,ID,FOLLOW_ID_in_newtraincommand85); 

                    }
                    break;

            }

             response = newTrainCommand.execute((ID1!=null?ID1.getText():null)); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "newtraincommand"


    // $ANTLR start "newwagoncommand"
    // /home/matthijs/paf/RichRail.g:53:1: newwagoncommand : 'new' 'wagon' ( ID )? ( 'numseats' NUMBER )? ;
    public final void newwagoncommand() throws RecognitionException {
        Token ID2=null;
        Token NUMBER3=null;

        try {
            // /home/matthijs/paf/RichRail.g:53:16: ( 'new' 'wagon' ( ID )? ( 'numseats' NUMBER )? )
            // /home/matthijs/paf/RichRail.g:54:2: 'new' 'wagon' ( ID )? ( 'numseats' NUMBER )?
            {
            match(input,8,FOLLOW_8_in_newwagoncommand98); 
            match(input,10,FOLLOW_10_in_newwagoncommand100); 
            // /home/matthijs/paf/RichRail.g:54:16: ( ID )?
            int alt5=2;
            int LA5_0 = input.LA(1);

            if ( (LA5_0==ID) ) {
                alt5=1;
            }
            switch (alt5) {
                case 1 :
                    // /home/matthijs/paf/RichRail.g:54:16: ID
                    {
                    ID2=(Token)match(input,ID,FOLLOW_ID_in_newwagoncommand102); 

                    }
                    break;

            }

            // /home/matthijs/paf/RichRail.g:54:20: ( 'numseats' NUMBER )?
            int alt6=2;
            int LA6_0 = input.LA(1);

            if ( (LA6_0==11) ) {
                alt6=1;
            }
            switch (alt6) {
                case 1 :
                    // /home/matthijs/paf/RichRail.g:54:21: 'numseats' NUMBER
                    {
                    match(input,11,FOLLOW_11_in_newwagoncommand106); 
                    NUMBER3=(Token)match(input,NUMBER,FOLLOW_NUMBER_in_newwagoncommand108); 

                    }
                    break;

            }

             response = newWagonCommand.execute((ID2!=null?ID2.getText():null), (NUMBER3!=null?NUMBER3.getText():null) != null ? new Integer(Integer.parseInt((NUMBER3!=null?NUMBER3.getText():null))) : null); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "newwagoncommand"


    // $ANTLR start "addcommand"
    // /home/matthijs/paf/RichRail.g:57:1: addcommand : 'add' add= ID 'to' to= ID ;
    public final void addcommand() throws RecognitionException {
        Token add=null;
        Token to=null;

        try {
            // /home/matthijs/paf/RichRail.g:57:11: ( 'add' add= ID 'to' to= ID )
            // /home/matthijs/paf/RichRail.g:58:2: 'add' add= ID 'to' to= ID
            {
            match(input,12,FOLLOW_12_in_addcommand122); 
            add=(Token)match(input,ID,FOLLOW_ID_in_addcommand126); 
            match(input,13,FOLLOW_13_in_addcommand128); 
            to=(Token)match(input,ID,FOLLOW_ID_in_addcommand132); 
             response = addCommand.execute((add!=null?add.getText():null), (to!=null?to.getText():null)); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "addcommand"


    // $ANTLR start "getcommand"
    // /home/matthijs/paf/RichRail.g:61:1: getcommand : 'getnumseats' type ID ;
    public final void getcommand() throws RecognitionException {
        Token ID5=null;
        RichRailParser.type_return type4 = null;


        try {
            // /home/matthijs/paf/RichRail.g:61:11: ( 'getnumseats' type ID )
            // /home/matthijs/paf/RichRail.g:62:2: 'getnumseats' type ID
            {
            match(input,14,FOLLOW_14_in_getcommand144); 
            pushFollow(FOLLOW_type_in_getcommand146);
            type4=type();

            state._fsp--;

            ID5=(Token)match(input,ID,FOLLOW_ID_in_getcommand148); 
             response = getNumSeatsCommand.execute((type4!=null?input.toString(type4.start,type4.stop):null), (ID5!=null?ID5.getText():null)); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "getcommand"


    // $ANTLR start "delcommand"
    // /home/matthijs/paf/RichRail.g:65:1: delcommand : 'delete' type ID ;
    public final void delcommand() throws RecognitionException {
        Token ID7=null;
        RichRailParser.type_return type6 = null;


        try {
            // /home/matthijs/paf/RichRail.g:65:11: ( 'delete' type ID )
            // /home/matthijs/paf/RichRail.g:66:2: 'delete' type ID
            {
            match(input,15,FOLLOW_15_in_delcommand160); 
            pushFollow(FOLLOW_type_in_delcommand162);
            type6=type();

            state._fsp--;

            ID7=(Token)match(input,ID,FOLLOW_ID_in_delcommand164); 
             response = deleteCommand.execute((type6!=null?input.toString(type6.start,type6.stop):null), (ID7!=null?ID7.getText():null)); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "delcommand"


    // $ANTLR start "remcommand"
    // /home/matthijs/paf/RichRail.g:69:1: remcommand : 'remove' remove= ID 'from' from= ID ;
    public final void remcommand() throws RecognitionException {
        Token remove=null;
        Token from=null;

        try {
            // /home/matthijs/paf/RichRail.g:69:11: ( 'remove' remove= ID 'from' from= ID )
            // /home/matthijs/paf/RichRail.g:70:2: 'remove' remove= ID 'from' from= ID
            {
            match(input,16,FOLLOW_16_in_remcommand176); 
            remove=(Token)match(input,ID,FOLLOW_ID_in_remcommand180); 
            match(input,17,FOLLOW_17_in_remcommand182); 
            from=(Token)match(input,ID,FOLLOW_ID_in_remcommand186); 
             response = removeCommand.execute((remove!=null?remove.getText():null), (from!=null?from.getText():null)); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "remcommand"

    public static class type_return extends ParserRuleReturnScope {
    };

    // $ANTLR start "type"
    // /home/matthijs/paf/RichRail.g:73:1: type : ( 'train' | 'wagon' );
    public final RichRailParser.type_return type() throws RecognitionException {
        RichRailParser.type_return retval = new RichRailParser.type_return();
        retval.start = input.LT(1);

        try {
            // /home/matthijs/paf/RichRail.g:73:5: ( 'train' | 'wagon' )
            // /home/matthijs/paf/RichRail.g:
            {
            if ( (input.LA(1)>=9 && input.LA(1)<=10) ) {
                input.consume();
                state.errorRecovery=false;
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                throw mse;
            }


            }

            retval.stop = input.LT(-1);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "type"

    // Delegated rules


 

    public static final BitSet FOLLOW_newcommand_in_command39 = new BitSet(new long[]{0x0000000000000082L});
    public static final BitSet FOLLOW_addcommand_in_command43 = new BitSet(new long[]{0x0000000000000082L});
    public static final BitSet FOLLOW_getcommand_in_command47 = new BitSet(new long[]{0x0000000000000082L});
    public static final BitSet FOLLOW_delcommand_in_command51 = new BitSet(new long[]{0x0000000000000082L});
    public static final BitSet FOLLOW_remcommand_in_command55 = new BitSet(new long[]{0x0000000000000082L});
    public static final BitSet FOLLOW_7_in_command58 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_newtraincommand_in_newcommand68 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_newwagoncommand_in_newcommand72 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_8_in_newtraincommand81 = new BitSet(new long[]{0x0000000000000200L});
    public static final BitSet FOLLOW_9_in_newtraincommand83 = new BitSet(new long[]{0x0000000000000012L});
    public static final BitSet FOLLOW_ID_in_newtraincommand85 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_8_in_newwagoncommand98 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_10_in_newwagoncommand100 = new BitSet(new long[]{0x0000000000000812L});
    public static final BitSet FOLLOW_ID_in_newwagoncommand102 = new BitSet(new long[]{0x0000000000000802L});
    public static final BitSet FOLLOW_11_in_newwagoncommand106 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_NUMBER_in_newwagoncommand108 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_12_in_addcommand122 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_ID_in_addcommand126 = new BitSet(new long[]{0x0000000000002000L});
    public static final BitSet FOLLOW_13_in_addcommand128 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_ID_in_addcommand132 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_14_in_getcommand144 = new BitSet(new long[]{0x0000000000000600L});
    public static final BitSet FOLLOW_type_in_getcommand146 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_ID_in_getcommand148 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_15_in_delcommand160 = new BitSet(new long[]{0x0000000000000600L});
    public static final BitSet FOLLOW_type_in_delcommand162 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_ID_in_delcommand164 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_16_in_remcommand176 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_ID_in_remcommand180 = new BitSet(new long[]{0x0000000000020000L});
    public static final BitSet FOLLOW_17_in_remcommand182 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_ID_in_remcommand186 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_set_in_type0 = new BitSet(new long[]{0x0000000000000002L});

}